package org.jdsm.flow.contact;

import org.jdsm.flow.contact.dao.IContactDAO;
import org.jdsm.flow.contact.impl.IMailSender;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;
import java.util.List;

/**
 * User: mikom
 * Date: 2/6/13
 * Time: 4:36 PM
 */
public class ContactService implements IContactService {
    private static final Logger log = LoggerFactory.getLogger(ContactService.class);
    @Resource
    private IContactDAO contactDAO;
    @Resource
    private IMailSender mailSender;
    @Override
    public void send(IContactFeedBack feedBack) {
        boolean result  = mailSender.send(feedBack.getEmail(), feedBack.getEmail(), feedBack.getMessage());
        log.debug("feedback:{} was send and saved in DB:{}", result);
    }

    @Override
    public List<IContactEntity> getContacts() {
        return contactDAO.getContacts();
    }

    @Override
    public void addContact(IContactEntity contactEntity) {
        contactDAO.addContact(contactEntity);
    }

    @Override
    public IContactEntity loadContact(IContactEntity contactEntity){
        return contactDAO.loadContact(contactEntity);
    }

    @Override
    public void saveFeedBack(IContactFeedBack feedBack) {
        contactDAO.saveFeedBack(feedBack);
        send(feedBack);
    }

    @Override
    public void removeContact(IContactEntity contactEntity) {
        contactDAO.removeContact(contactEntity);
    }
}
